package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constants;
import com.bjpowernode.manager.RedisManager;
import com.bjpowernode.mapper.TDicValueMapper;
import com.bjpowernode.model.TDicValue;
import com.bjpowernode.model.TUser;
import com.bjpowernode.service.TDicService;
import com.bjpowernode.util.CacheUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class TDicServiceImpl implements TDicService {
    @Resource
    TDicValueMapper tDicValueMapper;
    @Resource
    RedisManager redisManager;
    @Override
    public List<TDicValue> getDicValueByTypeCode(String typeCode) {
        List<TDicValue> TDicValueList = CacheUtils.getCacheData(
                () -> (List<TDicValue>)redisManager.getValue(Constants.REDIS_OWNER_KEY),
                () -> tDicValueMapper.selectByTypeCode(typeCode),
                (t) -> redisManager.setValue(Constants.REDIS_OWNER_KEY, t, Constants.OWNER_EXPIRE_TIME, TimeUnit.MINUTES)
        );
        return TDicValueList;
    }
}
